/*
 * @Date: 2023-03-23 10:24:56
 * @LastEditors: Chuying
 * @LastEditTime: 2023-03-23 10:57:42
 * @Description: 响应拦截
 */
import { Injectable, NestInterceptor, CallHandler } from '@nestjs/common';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';

interface result<T> {
  result: T;
}

@Injectable()
export class Response<T = any> implements NestInterceptor {
  intercept(context, next: CallHandler): Observable<result<T>> {
    return next.handle().pipe(
      map((data) => {
        return {
          result: data,
          status: 0,
          success: true,
          message: '成功',
        };
      }),
    );
  }
}
